<template>
	<view class="page friend-new">
		<nav-bar :btn="false" back>
			<text>新朋友</text>
			<template #right>
				<view @click="handleNew">添加</view>
			</template>
		</nav-bar>
		<view class="new-wrap mt-20">
			<view v-for="item in newFriendList" :key="item.id" class="new-item">
				<head-image :name="item.nickName" :online="item.online" :url="item.headImage" size="small"></head-image>
				<view class="flex-1 new-desc">
					<view class="name">{{item.nickName}}</view>
					<!-- <view>来源：{{item.form}}</view>
					<view>备注：{{item.remark}}</view> -->
				</view>
				<view class="btn-wrap">
					<view v-if="item.needAgree" @click="handleAgree(1,item)" style="background-color: #2f81fb;color: #fff;">同意</view>
					<!-- <text v-else>已同意</text> -->
					<view v-if="item.needAgree" @click="handleAgree(2,item)" style="margin-left: 30rpx;">拒绝</view>
					<view v-else class="" style="color: #999;">
						等待对方同意
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newFriendList: []
			}
		},
		methods: {
			handleAgree(val, data) {
				let title = '确定同意该好友申请';
				if (val == 2) {
					title = '确定拒绝该好友申请'
				}
				uni.showModal({
					content: title,
					success: (res) => {
						if (res.cancel) return;
						this.$http({
							url: `/friend/checkStatus`,
							method: 'POST',
							data: {
								friendId: data.id,
								checkStatus: val
							}
						}).then(() => {
							this.friendStore.loadFriend();
							uni.navigateBack();
						});
					}
				})
				// uni.navigateTo({
				// 	url: '/pages/friend/friend-agree'
				// })
			},
			getNewList() {
				this.$http({
					url: '/friend/findNewFriends',
					type: 'GET',
				}).then(res => {
					this.newFriendList = res || [];
				})
			},
			handleNew() {
				console.log('add~~~~~')
				uni.navigateTo({
					url: '/pages/friend/friend-add'
				})
			},
		},
		onShow() {
			this.getNewList();
		}
	}
</script>

<style lang="scss" scoped>
	.friend-new {
		position: relative;
		display: flex;
		flex-direction: column;
	}

	.flex-1 {
		flex: 1;
	}

	.mt-20 {
		margin-top: 20rpx;
	}

	.mt-32 {
		margin-top: 32rpx;
	}

	.new-wrap {
		background-color: #fff;

		image {
			width: 80rpx;
			height: 80rpx;
		}

		.new-item {
			padding: 20rpx;
			display: flex;

			.new-desc {
				display: inline-flex;
				align-items: center;
				font-size: 26rpx;
				color: #9196A1;
				margin-left: 20rpx;
				line-height: 40rpx;
			}

			.name {
				font-size: 30rpx;
				color: #000;
			}

			.btn-wrap {
				color: #9196A1;
				display: inline-flex;
				align-items: center;
				justify-content: center;

				view {
					font-size: 28rpx;
					padding: 12rpx 32rpx;
					border-radius: 10rpx;
					border: solid 1rpx #ccc;
				}

				text {
					font-size: 26rpx;
					color: #9196A1;
				}
			}


		}
	}
</style>